/**
 * @file 公共方法
 * @date 2017-09-24
 * @author wangyu
 */

'use strict';

let $ = require('jquery');
require('../../libs/jquery.cookie.js');
let Layer = require('../../libs/layer');

let util = {
    isEmpty(str) {
        let ret = true;
		if(str && str!=undefined && str!=null && str!="null" && str!="undefined" && str!=""){
			ret = false;
		}
		return ret;
    },
    intToCapital(str) {
    	let capital = '';
		let len = str.length-1;
		let idxs = ['0','1','2','3','4','5','6','7','8','9'];
		let capitalSize = ['一','二','三','四','五','六','七','八','九','十'];
		let index=$.inArray(str,idxs);
		capital = capitalSize[index];
		return capital;
    },
    initExamTitle(index) {
    	var arr = ['自我介绍', '朗诵', '讲故事', '演讲', '看图说话', '口头作文', '主持', '辩论','才艺展示'];
    	return arr[index];
    },
    initToCapitalNumber(index) {
    	return "一二三四五六七八九十".charAt(index);
    },
    initLogin(prefer,LoginType){
        let userCode = $.cookie("userCode");
        let CheckUrl = "";
        let userType = $.cookie("userType")
        if(this.isEmpty(userType)){
            let urlLogin = "/indiviLogin.html?prefer=";
            if(LoginType == 1){
               urlLogin = "/agencyLogin.html?prefer=" 
            }
            CheckUrl=urlLogin+prefer;
            Layer.msg('获取信息失败</br>请重新登录');
            setTimeout(function(){
                window.location.href = CheckUrl;
            },2000);
            
        }else{
            if(LoginType != userType){
               let urlLogin = "/indiviLogin.html?prefer=";
                if(LoginType == 1){
                   urlLogin = "/agencyLogin.html?prefer=" 
                }
                CheckUrl=urlLogin+prefer;
                Layer.msg('获取信息失败</br>请重新登录');
                setTimeout(function(){
                    window.location.href = CheckUrl;
                },2000); 
            }else{
                return;
            }
        }
    },
    //清除所有cookie函数  
    clearAllCookie() {  
        var keys = document.cookie.match(/[^ =;]+(?=\=)/g);  
        if(keys) {  
            for(var i = keys.length; i--;)  
                document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString()  
        }  
    }  
}

export default util;
